﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/*
public class Singleton<T> where T : new()
{
    private static T instance;
    public static T Instance { get { return instance; } }
    static Singleton()
    {
        instance = new T();
    }

    protected Singleton()
    {
    }
}
*/
public class Singleton<T> where T : new()
{
    private static T instance;
    private static object syncRoot = new Object();

    protected Singleton() { }

    public static T Instance
    {
        get
        {
            if (instance == null)
            {
                lock (syncRoot)
                {
                    if (instance == null)
                        instance = new T();
                }
            }

            return instance;
        }
        set { instance = value; }
    }
}
